package com.ruoyi.wms.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.wms.domain.WmsInventorySheetDetails;
import com.ruoyi.wms.mapper.WmsInventorySheetMapper;
import com.ruoyi.wms.domain.WmsInventorySheet;
import com.ruoyi.wms.service.IWmsInventorySheetService;

/**
 * 盘点管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-03-24
 */
@Service
public class WmsInventorySheetServiceImpl implements IWmsInventorySheetService 
{
    @Autowired
    private WmsInventorySheetMapper wmsInventorySheetMapper;

    /**
     * 查询盘点管理
     * 
     * @param inventorySheetUuid 盘点管理主键
     * @return 盘点管理
     */
    @Override
    public WmsInventorySheet selectWmsInventorySheetByInventorySheetUuid(String inventorySheetUuid)
    {
        return wmsInventorySheetMapper.selectWmsInventorySheetByInventorySheetUuid(inventorySheetUuid);
    }
  @Override
    public WmsInventorySheet selectWmsInventorySheetByUuid(String inventorySheetUuid)
    {
        return wmsInventorySheetMapper.selectWmsInventorySheetByUuid(inventorySheetUuid);
    }
 @Override
    public WmsInventorySheet selectWmsInventorySheetLoss(String inventorySheetUuid)
    {
        return wmsInventorySheetMapper.selectWmsInventorySheetLoss(inventorySheetUuid);
    }

    /**
     * 查询盘点管理列表
     * 
     * @param wmsInventorySheet 盘点管理
     * @return 盘点管理
     */
    @Override
    public List<WmsInventorySheet> selectWmsInventorySheetList(WmsInventorySheet wmsInventorySheet)
    {
        return wmsInventorySheetMapper.selectWmsInventorySheetList(wmsInventorySheet);
    }
 @Override
    public List<WmsInventorySheet> listWmsInventory(WmsInventorySheet wmsInventorySheet)
    {
        return wmsInventorySheetMapper.listWmsInventory(wmsInventorySheet);
    }

    /**
     * 新增盘点管理
     * 
     * @param wmsInventorySheet 盘点管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertWmsInventorySheet(WmsInventorySheet wmsInventorySheet)
    {
        wmsInventorySheet.setCreateTime(DateUtils.getNowDate());
        int rows = wmsInventorySheetMapper.insertWmsInventorySheet(wmsInventorySheet);
        insertWmsInventorySheetDetails(wmsInventorySheet);
        return rows;
    }

    /**
     * 修改盘点管理
     * 
     * @param wmsInventorySheet 盘点管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateWmsInventorySheet(WmsInventorySheet wmsInventorySheet)
    {
        wmsInventorySheet.setUpdateTime(DateUtils.getNowDate());
        wmsInventorySheetMapper.deleteWmsInventorySheetDetailsByFkInventorySheetUuid(wmsInventorySheet.getInventorySheetUuid());
        insertWmsInventorySheetDetails(wmsInventorySheet);
        return wmsInventorySheetMapper.updateWmsInventorySheet(wmsInventorySheet);
    }

    /**
     * 批量删除盘点管理
     * 
     * @param inventorySheetUuids 需要删除的盘点管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteWmsInventorySheetByInventorySheetUuids(String[] inventorySheetUuids)
    {
        wmsInventorySheetMapper.deleteWmsInventorySheetDetailsByFkInventorySheetUuids(inventorySheetUuids);
        return wmsInventorySheetMapper.deleteWmsInventorySheetByInventorySheetUuids(inventorySheetUuids);
    }

    /**
     * 删除盘点管理信息
     * 
     * @param inventorySheetUuid 盘点管理主键
     * @return 结果
     */
    @Override
    public int deleteWmsInventorySheetByInventorySheetUuid(String inventorySheetUuid)
    {
        wmsInventorySheetMapper.deleteWmsInventorySheetDetailsByFkInventorySheetUuid(inventorySheetUuid);
        return wmsInventorySheetMapper.deleteWmsInventorySheetByInventorySheetUuid(inventorySheetUuid);
    }

    /**
     * 新增盘点明细信息
     * 
     * @param wmsInventorySheet 盘点管理对象
     */
    public void insertWmsInventorySheetDetails(WmsInventorySheet wmsInventorySheet)
    {
        List<WmsInventorySheetDetails> wmsInventorySheetDetailsList = wmsInventorySheet.getWmsInventorySheetDetailsList();
        String inventorySheetUuid = wmsInventorySheet.getInventorySheetUuid();
        if (StringUtils.isNotNull(wmsInventorySheetDetailsList))
        {
            List<WmsInventorySheetDetails> list = new ArrayList<WmsInventorySheetDetails>();
            for (WmsInventorySheetDetails wmsInventorySheetDetails : wmsInventorySheetDetailsList)
            {
                wmsInventorySheetDetails.setFkInventorySheetUuid(inventorySheetUuid);
                list.add(wmsInventorySheetDetails);
            }
            if (list.size() > 0)
            {
                wmsInventorySheetMapper.batchWmsInventorySheetDetails(list);
            }
        }
    }
}
